define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'yikatong/xfcardxf/index',
                    add_url: 'yikatong/xfcardxf/add',
                    edit_url: 'yikatong/xfcardxf/edit',
                    del_url: 'yikatong/xfcardxf/del',
                    multi_url: 'yikatong/xfcardxf/multi',
                    table: 'yikatong_xfcardxf',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'empno', title: __('Empno')},
                        {field: 'cardno', title: __('Cardno')},
                        {field: 'cardtype', title: __('Cardtype'), formatter: function(value){ var statuses = {0: '卡号', 1:'序列号', 2:'变种号'}; return statuses[value]; }},
                        {field: 'gatime', title: __('Gatime')},
                        {field: 'sktime', title: __('Sktime')},
                        // {field: 'cs', title: __('Cs')},
                        // {field: 'dics', title: __('Dics')},
                        // {field: 'tac', title: __('Tac')},
                        // {field: 'cardkjh', title: __('Cardkjh')},
                        // {field: 'opempno', title: __('Opempno')},
                        {field: 'addr', title: __('Addr')},
                        {field: 'jh', title: __('Jh')},
                        {field: 'busiid', title: __('Busiid')},
                        {field: 'teamname', title: __('Teamname')},
                        {field: 'secno', title: __('Secno')},
                        {field: 'xfgoodid', title: __('Xfgoodid')},
                        {field: 'xfgoodamount', title: __('Xfgoodamount')},
                        // {field: 'xfgoodamount2', title: __('Xfgoodamount2')},
                        {field: 'xfje', title: __('Xfje')},
                        {field: 'xfaccount', title: __('Xfaccount'), formatter: function(value){ var statuses = {0: '个人', 1:'补贴'}; return statuses[value]; }},
                        {field: 'xfye', title: __('Xfye')},
                        {field: 'gzje', title: __('Gzje')},
                        {field: 'gztime', title: __('Gztime')},
                        {field: 'jlvalue', title: __('Jlvalue')},
                        // {field: 'tagdc', title: __('Tagdc')},
                        // {field: 'tagnocfm', title: __('Tagnocfm')},
                        // {field: 'edittag', title: __('Edittag')},
                        // {field: 'opsourceid', title: __('Opsourceid')},
                        // {field: 'opsourceempid', title: __('Opsourceempid')},
                        // {field: 'pdjg', title: __('Pdjg')},
                        // {field: 'photo', title: __('Photo')},
                        // {field: 'tagpf10', title: __('Tagpf10')},
                        // {field: 'tagpf11', title: __('Tagpf11')},
                        // {field: 'row_number', title: __('Row_number')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});